package com.haoan.index.service.impl;


import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoan.index.common.enums.ValiFlag;

import com.haoan.index.mapper.AnnouncementMapper;
import com.haoan.index.domain.Announcement;
import com.haoan.index.service.AnnouncementService;

/**
 * 公告/新闻资讯Service业务层处理
 * 
 * @author autoGen
 * @date 2025-01-03
 */
@Service
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper,Announcement> implements AnnouncementService
{
    /**
     * 查询公告/新闻资讯
     * 
     * @param id 公告/新闻资讯主键
     * @return 公告/新闻资讯
     */
    @Override
    public Announcement selectAnnouncementById(Long id)
    {
        return baseMapper.selectById(id);
    }

    /**
     * 查询公告/新闻资讯列表
     * 
     * @param announcement 公告/新闻资讯
     * @return 公告/新闻资讯
     */
    @Override
    public List<Announcement> selectAnnouncementList(Announcement announcement)
    {
        LambdaQueryWrapper<Announcement> queryWrapper = new LambdaQueryWrapper<>();
        //todo 添加查询条件
        queryWrapper.eq(announcement.getId() != null, Announcement::getId, announcement.getId());
        queryWrapper.eq(announcement.getType() != null, Announcement::getType, announcement.getType());
        queryWrapper.eq(announcement.getTitle() != null, Announcement::getTitle, announcement.getTitle());
        queryWrapper.eq(announcement.getPicture() != null, Announcement::getPicture, announcement.getPicture());
        queryWrapper.eq(announcement.getBrief() != null, Announcement::getBrief, announcement.getBrief());
        queryWrapper.eq(announcement.getDetail() != null, Announcement::getDetail, announcement.getDetail());
        queryWrapper.eq(announcement.getCreateTime() != null, Announcement::getCreateTime, announcement.getCreateTime());
        queryWrapper.eq(announcement.getCreateBy() != null, Announcement::getCreateBy, announcement.getCreateBy());
        queryWrapper.eq(announcement.getUpdateTime() != null, Announcement::getUpdateTime, announcement.getUpdateTime());
        queryWrapper.eq(announcement.getUpdateBy() != null, Announcement::getUpdateBy, announcement.getUpdateBy());
        queryWrapper.eq(Announcement::getValiFlag,ValiFlag.VALID );
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 新增公告/新闻资讯
     * 
     * @param announcement 公告/新闻资讯
     * @return 结果
     */
    @Transactional
    @Override
    public int insertAnnouncement(Announcement announcement)
    {
        return baseMapper.insert(announcement);
    }

    /**
     * 修改公告/新闻资讯
     * 
     * @param announcement 公告/新闻资讯
     * @return 结果
     */
    @Transactional
    @Override
    public int updateAnnouncement(Announcement announcement)
    {
        return baseMapper.updateById(announcement);
    }

    /**
     * 批量删除公告/新闻资讯
     * 
     * @param ids 需要删除的公告/新闻资讯主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteAnnouncementByIds(Long [] ids)
    {
        Announcement announcement = new Announcement();
        announcement.setValiFlag(ValiFlag.INVALID);
        LambdaQueryWrapper<Announcement> updQw = new LambdaQueryWrapper<>();
        updQw.in(Announcement::getId, ids);
        return baseMapper.update(announcement, updQw);
    }

    /**
     * 删除公告/新闻资讯信息
     * 
     * @param id 公告/新闻资讯主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteById(Long id)
    {
        Announcement announcement = getById(id);
        announcement.setValiFlag(ValiFlag.INVALID);
        return baseMapper.updateById(announcement);
    }
}
